package org.ucn.dmaa0914.temadesign.group2.controlLayer;
import org.ucn.dmaa0914.temadesign.group2.modelLayer.Person;
import org.ucn.dmaa0914.temadesign.group2.modelLayer.PersonContainer;
import java.util.HashSet;

/**
 * The person controller class manages all interaction between the person model and it's view(s).
 * 
 * @author Kim Johannsen
 * @version 04-11-2014
 */
public class PersonController
{
    /**
     * Constructor for objects of class PersonController
     */
    public PersonController()
    {
        
    }

    /**
     * Create a person with the given data
     * @return The new person object which has been created
     */
    public Person createPerson(String name, String address, int zip, String city, String phone, String email)
    {
        Person p = new Person(name, address, zip, city, phone, email);
        PersonContainer.instance.addPerson(p);
        return p;
    }
    
    /**
     * Looks up a person by he's id.
     * 
     * @param id The id of the person to find.
     * @return The person with the specified id, or null if the person is not found.
     */
    public Person findPerson(int id)
    {
        return PersonContainer.instance.findPerson(id);
    }
    
    /**
     * Looks up a person by he's phone number.
     * 
     * @param phone The phone number of the person to look for
     * @return The person with the specified phone number, or null if the person is not found.
     */
    public Person getPerson(String phone)
    {
        return PersonContainer.instance.getPerson(phone);
    }
    
    /**
     * Get all persons
     */
    public HashSet<Person> getAll()
    {
        return PersonContainer.instance.getAll();
    }
    
    /**
     * Updates a person's info and also refreshes lookup data in the PersonContainer
     */
    public void updatePerson(Person p, String name, String address, int zip, String city, String phone, String email)
    {
        p.setName(name);
        p.setAddress(address);
        p.setZip(zip);
        p.setCity(city);
        p.setPhone(phone);
        p.setEmail(email);
    }
    
    /**
     * Deletes a person from the database if present
     * 
     * @param p The person to delete
     */
    public void deletePerson(Person p)
    {
        PersonContainer.instance.deletePerson(p);
    }
}
